#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
#  Project: Kelindo - Unsupervised Music Organizer  
#  Author: Nicola Bicocchi <nicola.bicocchi@gmail.com>, Nicolo' Torreggiani <nicolo.torreggiani@gmail.com>, Gianluca Puglia <gianluca.puglia@gmail.com>, Matteo Senardi <pualien@gmail.com>
#  Copyright: 2013 Nicola Bicocchi, Nicolo' Torreggiani, Gianluca Puglia, Matteo Senardi
#  License: GPL-2+
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
# 
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#  more details.
# 
# On Debian GNU/Linux systems, the full text of the GNU General Public License
# can be found in the file /usr/share/common-licenses/GPL-2.
##

import Queue

from kelindo.libkelindo import Kelindo

class cmdKelindo:
    
    def __init__(self):
        self.path = '/home/nicola/Music'
        self.core = Kelindo(self.path)
        self.core.subscribe(self.__core_callbacks)
        
        self.queue = Queue.Queue()
        self.core.find_candidate_albums(self.queue)
        return
    
    def __core_callbacks(self, event):
        print event.key
        
        if event.key == 'no_candidate':
            print 'no_albums_found'              

        if event.key == 'finded_candidate':
            candidates = self.core.get_stats()['OK']
            print '%d candidate (%d folders)' % (candidates, len(self.core.albums))
            
        if event.key == 'finish_finding_candidate':
            print 'finish_finding_candidate'  
            #self.finished = True
            #self.phase = self.core.get_stats()['OK'] / 10
            #if self.phase is 0:
            #    self.phase = 1
            #self.total = self.core.get_stats()['OK'] + self.phase
                
        if event.key == 'classificated_album':
            album = event.album
            print album.status
            total = self.core.stat_start['OK']
            done = total - self.core.get_stats()['OK']
            print 'Classifying album %d/%d...' % (done, total)
            #self.fraction = (done + (float(self.phase) / 2)) / float(self.total)
            #self.progress_bar.set_fraction(self.fraction)
            #self.progress_bar.set_text(str(int(self.fraction * 100)) + '%')
            
        if event.key == 'classifing_albums_done': 
            print 'done'

if __name__ == '__main__':
    k = cmdKelindo()
    
